﻿#ifndef TESTGRPCPLUGINIMP_H
#define TESTGRPCPLUGINIMP_H

#pragma once
#include "stdfax.h"
#include "IConfigService.h"
#include "TestgRpcServer.h"

#ifdef _WINDOWS
#ifdef   IGRPC_DLL_EXPORT
#define  IGRPC_DLL __declspec(dllexport)
#else
#define  IGRPC_DLL __declspec(dllimport)
#endif
//then for linux
#else
#define  IGRPC_DLL __attribute__((visibility("default")))
#endif

/*
typedef struct gRpcServerServiceName
{
    char * ip;
    int port;
}gRpcServerServiceName;
*/


class TestgRpcPluginImp : public IBundleActivator
{
public:
    static TestgRpcPluginImp * Instance();
    ILogger * GetLogger();
    IGRPCService * GetGRPCService();

private:
    ~TestgRpcPluginImp();
    TestgRpcPluginImp();

    bool setServiceMnager(IBundleContext* pBundleContext);
    bool setBundleContext(IBundleContext* pBundleContext);
    bool setAllocator(IBundleContext* pBundleContext);
    bool setIniConfigParser(IBundleContext* pBundleContext);
    bool setLogger(IBundleContext* pBundleContext);
    bool setGRPCService(IBundleContext* pBundleContext);
    //bool setClusterManagerFac(IBundleContext* pBundleContext);
public:
    virtual bool MKRAPI Start(IBundleContext * pBundleContext);
    virtual bool MKRAPI Stop(IBundleContext * pBundleContext);

private:
    //grpc::Service * service;
    std::string server_address;
    bool enpollflag;
    int minnum;
    int maxnum;
    static TestgRpcPluginImp * m_pInstance;
    IBundleContext * m_pBundCnt;
    IServiceManager * m_pServMgr;
    IAllocator * m_pAlloc;
    IINIConfigParser * m_pIniParser;
    ILogger * m_pLogger;
    //IClusterFactory * m_pClusterFactory;
    IGRPCService * m_pGRPCService;

private:
    bool readConfig(std::string server_address);
    //bool processMapInfo(std::map<std::string,ServerServiceName> &mapServiceInfo);
    //void registerToCluster(std::string &strServiceName,ServerServiceName &info);
};

#endif // TESTGRPCPLUGINIMP_H
